package com.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.Map;

public class JsonUtil
{
    //将对象转换位json字符串
    public static String toJsonStr( Object object )
    {
        return JSON.toJSONString( object );
    }

    //将带有日期时间的对象转换位字符串
    public static String toJsonStrWithDateTime( Object object )
    {
        return JSON.toJSONStringWithDateFormat( object , "yyyy-MM-dd HH:mm:ss" );
    }

    //返回成功与否的json信息
    public static String successOrNotJsonStr( Integer resultCode )
    {
        return "{\"success\":" + (resultCode>0) + ",\"message\":" +  resultCode  + "}";
    }

    //组装jsr303验证提示jsonstr
    public static String errorMessageJsonStr( Map<String,String> errorMessage )
    {
        JSONObject jb = new JSONObject();
        jb.put( "errorMessage" , errorMessage );

        return jb.toJSONString();
    }

}
